// UP回到顶部
$(window).scroll(function () {
  var scroll_len = $(window).scrollTop();
  if (scroll_len > 200) {$('.QZ-up').fadeIn();} else {$('.QZ-up').fadeOut();}
});
$("body").append("<div class='QZ-up icon'></div>")
$('.QZ-up').click(function () {
  $("body,html").animate({scrollTop: 0}, 300);
});
  //阻止事件冒泡
  function stopNextEvent(evt) {
    var e = (evt) ? evt : window.event;
    if (window.event) {
        e.cancelBubble = true;// ie下阻止冒泡
    } else {
        //e.preventDefault();
        e.stopPropagation();// 其它浏览器下阻止冒泡
    }
}
$("body").click(function(obj, evt){
  $('.header-wrap .header-top .num').removeClass('active')
})
  //meun
$('.header-wrap .header-top .num').click(function (obj,evt) {
    stopNextEvent(evt);
    $(this).toggleClass('active')
})
// 点击晒筛选
$('.swiper-tab .screen').click(function (obj,evt) {
  stopNextEvent(evt);
  $(this).toggleClass('on')
  $('.layer_screen').slideToggle(200);
  if( $(this).hasClass('on')){
    var h=$(this).parents(".swiper-tab").find(".layer_screen").offset().top+1
    $(this).parents(".swiper-tab").find(".layer_screen").animate({"height":$('body').height()-h+'px'},100)
    $(this).parents(".swiper-tab").find(".layer_screen .screenbox").css({"max-height":$('body').height()-h-100+'px'})
  }
})

   //PAGE分页
$(".page>span .cbtn").css("display", "none");
$(".page>span").click(function () {
    $(this).children("div").show();
})
$(document).click(function () {
    $(".page>span .cbtn").css("display", "none");
})
$(".page>span .cbtn,.page>span").click(function (event) {
    event.stopPropagation();
});
  // 切换click
$(".switchwarp-ck .switchlabe .tab").click(function() {
    $(this).addClass('on').siblings().removeClass('on');
    var i=$(this).index();
    $(this).parents(".switchwarp-ck").find(".switchbox .switchitem ").eq(i).show().siblings().hide();
    $(this).parents(".switchwarp-ck").find(".switchmore a").eq(i).show().siblings().hide();
    $(window).trigger('scroll');
})
// 导航
if($(".swiper-nav .swiper-slide").size()>=1){
    var swipernav = new Swiper(".swiper-nav.swiper", {
        slidesPerView: 7,
      });
      $(".swiper-nav  .swiper-slide").each(function (index) {
        if ($(this).hasClass("on") && index>5) {
            var index_ = $(this).index();
            swipernav.slideTo(index_, false);//切换到第一个slide，速度为1秒;
        }
    })
}
// 列表页面导航
if($(".swiper-tab .swiper-slide").size()>=1){
  var swipernav2 = new Swiper(".swiper-tab .swiper", {
      slidesPerView: 4,
      spaceBetween: 8,
    });
}
  //首页的轮播
if ($(".swiper_lunbox .swiper .swiper-slide").size() >= 1) {
  var swiper = new Swiper('.swiper_lunbox .swiper', {
      lazy: {
        loadPrevNext: true,
      },
      loop:true,
      speed: 400,
      autoplay: {
          delay: 5000,
          disableOnInteraction: false,
      },
      pagination: {
          el: '.swiper_lunbox .swiper-pagination',
          clickable: true,
      },
  });
}

  //首页的分类
  if ($(".classification .swiper .swiper-slide").size() >= 1) {
    var classification_swiper = new Swiper('.classification .swiper', {
        slidesPerView: 2,
        grid: {
          fill: 'column',
          rows: 2,
        },
    });
  }

    // 组件分类
if($(".swiperMin1.grid .swiper-slide").size()>=1){
  var swiperMin1 = new Swiper(".swiperMin1.grid .swiper", {
      slidesPerView: 3.03,
      observer:true,
      observeParents:true,
      grid: {
        fill: 'column',
        rows: 2,
      },
    });
}
    // 组件分类双行
  if($(".Min_app.grid .swiper-slide").size()>=1){
      var Min_appgrid = new Swiper(".Min_app.grid .swiper", {
          slidesPerView: 4.1,
          observer:true,
          observeParents:true,
          grid: {
            fill: 'column',
            rows: 2,
          },
        });
    }
  // 组件分类单行
  if($(".Min_app.auto .swiper-slide").size()>=1){
    var Min_appgrid = new Swiper(".Min_app.auto .swiper", {
        slidesPerView: 4.1,
        lazy: {
          loadPrevNext: true,
          // loadPrevNextAmount: 5,
      },
        observer:true,
        observeParents:true,
      });
  }
  // swiperauto
if($(".swiperauto .swiper-slide").size()>=1){
  var swiperauto = new Swiper(".swiperauto.swiper", {
      slidesPerView: 'auto',
      observer:true,
      observeParents:true,
      autoHeight: true, //高度随内容变化
        lazy: {
          loadPrevNext: true,
          loadPrevNextAmount: 5,
      },
      navigation: {
        nextEl: ".swipernext",
        prevEl: ".swiperprev",
      },
    });
}
  // swiper切换
// var swipername=''
if($(".swiperswitch .swiper .swiper-slide").size()>=1){
  $(".swiperswitch").each(function(i){
      let that=$(this);
      $(this).addClass("swiperswitchindex"+i);
       var swipername='swiperswitch'+i;
      swipername= new Swiper(".swiperswitchindex"+i+" .swiper", {
          slidesPerView: 'auto',
          spaceBetween: 20,
          autoHeight:true,
          observer:true,
          observeParents:true,
          resizeObserver: true,
          observeSlideChildren:true,
          lazy: {
              loadPrevNext: true,
              loadPrevNextAmount: 20,
            },
          on: {
              slideChangeTransitionStart: function (swiper, event) {
                  $(window).trigger('scroll');
                  that.find(".swiper-tab .tab").eq(this.activeIndex).addClass("on").siblings().removeClass('on')
              },
          },
  });
  $(".swiperswitchindex"+i+" .swiper-tab .tab").click(function(){
      $(this).addClass("on").siblings().removeClass('on');
      swipername.slideTo($(this).index(),500, false);//切换到第一个slide，速度为1秒;
    })
  })
}
// 游戏截图
function scroll_img_height(){
    var box=$(".swiperimgbox .swiper .swiper-slide").eq(1).find("img");
    var imgo = new Image();
        imgo.src = box.attr('src');
        imgo.onload=function(){
          var img_h=imgo.height;
          var img_w=imgo.width;
          var slide=1.04;
          if (img_h>img_w){
            $(".swiperimgbox").addClass('swiperimg-h')
            slide=2.5;
          }
          var swiperimgbox = new Swiper(".swiperimgbox .swiper", {
            slidesPerView: slide,
            observer:true,
            observeParents:true,
            spaceBetween: 8,
            lazy: {
              loadPrevNextAmount: 3,
                loadPrevNext: true,
            },
        });
      }
  }
if($(".swiperimgbox .swiper-slide").size()>=1){
    var time_ = window.setTimeout("scroll_img_height()",500);//使用字符串执行方法;
}
  	// 放大图片
if($('.swiperimgbox ').length>0 || $('.details_html img').length>0){
  var pswpHtml = '';
  pswpHtml +='<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true"><div class="pswp__bg"></div><div class="pswp__scroll-wrap"><div class="pswp__container"><div class="pswp__item"></div><div class="pswp__item"></div><div class="pswp__item"></div></div><div class="pswp__ui pswp__ui--hidden"><div class="pswp__top-bar"><div class="pswp__counter"></div><button class="pswp__button pswp__button--close" title="Close (Esc)"></button><button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button><button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button><div class="pswp__preloader"><div class="pswp__preloader__icn"><div class="pswp__preloader__cut"><div class="pswp__preloader__donut"></div></div></div></div></div><button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)"></button><button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)"></button><div class="pswp__caption"><div class="pswp__caption__center"></div></div></div></div></div>'
   $("body").append(pswpHtml);
   function pswpFun(els){
      if(els.length>0){
          els.find('p > img').on('click',function(){
                  var pswpElement = document.querySelectorAll('.pswp')[0];
              var items = new Array();
              $.each(els.find('p > img'), function(i, v) {
                      $(v).attr("rel", i);
                  items.push({
                      src: $(v).attr("src"),
                      w: $(v).width(),
                      h: $(v).height()
                  });
              });
              var options = { index: parseInt($(this).attr("rel")) };
              var gallery = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, items, options);
      
              if($(this).parents("a").length>0){
                     return;
                 }else{
                     gallery.init();
                 }
          });
      }
  }
  pswpFun($('.details_html '));
  if($('.swiperimgbox').length>0){
      $('.swiperimgbox').find('img').on('click',function(){
              var pswpElement = document.querySelectorAll('.pswp')[0];
          var items = new Array();
          $.each($('.swiperimgbox').find('img'), function(i, v) {
                  $(v).attr("rel", i);
              items.push({
                     src: $(v).attr("src"),
                     w: $(v).width(),
                     h: $(v).height()
              });
          });
          var options = { index: parseInt($(this).attr("rel")) };
          var gallery = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, items, options);
             gallery.init();
      });
  }
  
}
// 详情的高速下载
$(".downtop .checkbox").click(function(){
  $(this).toggleClass("checked");
  showquick()
})
function showquick(){
  if($(".downtop .checkbox").hasClass("checked")){
      $(".downtop .downbox .down.quick").show().siblings().hide();
  }else{
      $(".downtop .downbox .down.quick").hide().siblings().show();
  }
}
if($(".downtop .checkbox").size()>=1){
  showquick()
}